Repository navigation
Conversation
The Python code generator needs a schema's names in snake_case as the engine formats them, but generation reads schemas from introspection JSON and python-sdk itself is served before v1.0.0-beta.21, where Query.formatIdentifiers lives, so it can't ask the engine. helpers/names writes the names file (SNAKE:UPPERCASE map) with a verbatim copy of dagger/dagger's engine/naming at a pinned commit (naming/pin.go), keyed by the schema's __schemaVersion like formatIdentifiers(version:). A schema without Query.formatIdentifiers gets an empty file: that's the gate. It warns when a schema is newer than the release line the copy covers, and tests the copy against the engine's own vectors. Signed-off-by: Alex Suraci <alex@dagger.io>
Every generate command takes a names file (-n, as helpers/names writes it). For a schema with Query.formatIdentifiers (v1.0.0-beta.21 views), names come from it; schemas without it, and names missing from it, keep the legacy converter and generate byte-identical code. With the engine's names: - A method whose legacy-converted name differs (prerequisite_sh_as) keeps it as a deprecated alias. - Core enums extend the new ValueEnum: SCREAMING_SNAKE members holding the schema value they stand for, sent by value; the schema's other spellings (OCIMediaTypes) are deprecated aliases, and defaults use the canonical member. - A dependency module's enum whose @enumValue holds its own values stays a plain Enum, as before. Signed-off-by: Alex Suraci <alex@dagger.io>
From v1.0.0-beta.21 the engine names a module's declarations by its naming rules (get_url is getURL, Ready is READY), so the calls the runtime builds through the module's own interfaces must use those names. Before invoking a function of a module that declares interfaces, the runtime asks Query.formatIdentifiers, in batches, by raw query since the SDK files can't import bindings. The API being in the session's schema is the gate: the session is served in the module's view, so older modules keep the plain conversion. Interface arguments are now bound by their Python name. Signed-off-by: Alex Suraci <alex@dagger.io>
The engine reads `[imports.Dagger] dagger` from a dang.toml beside an entrypoint (dagger/dagger#14812) and serves it at v1.0.0-beta.20 without one. The entrypoint generated into a module now ships one, and the scope is generated in that version's view, so bindings and calls agree. A new module declares the engine it is created on, without build metadata, and so gets the engine's naming from beta.21. A module that already had an entrypoint but no dang.toml gets beta.20, what the engine already serves it, so regenerating never moves it silently. An existing dang.toml is kept. FunctionCachePolicy keeps its old spellings: they stay valid in every view. Signed-off-by: Alex Suraci <alex@dagger.io>
namesHelperTestCheck refuses a copy of engine/naming that differs from the pinned commit and runs the helper's tests. entrypointVersionCheck covers the version a generated entrypoint declares: new, existing without a dang.toml, and the module's own dang.toml. Signed-off-by: Alex Suraci <alex@dagger.io>
Core, each client and the global client are generated with the names file helpers/names writes from their schemas, so a scope read in a v1.0.0-beta.21 view gets the engine's names; any other gets an empty file and the code it always had. Signed-off-by: Alex Suraci <alex@dagger.io>
Re-pin the copy of engine/naming to dagger/dagger 3bae26f, where K8s and K3s are terms of their own. Released engines before v1.0.0-beta.21 (beta.19, beta.20) serve Query.formatIdentifiers in every v1 view but still name modules by their legacy rules, so the schema alone is not a sufficient gate there. The helper now takes the engine's version (-engine) and writes no names for a release before the cut; scope.dang passes it. Signed-off-by: Alex Suraci <alex@dagger.io>
The runtime's gate also checks Query.version: released engines before v1.0.0-beta.21 serve formatIdentifiers but name modules by their legacy rules. Calls through a module's own interfaces that return its enums (or lists of them) now read the members by the names the engine gave them (READY for Ready), the reverse of how they're sent. Signed-off-by: Alex Suraci <alex@dagger.io>
A module moving onto the generated entrypoint from a runtime whose manifest declares v1.0.0-beta.21 or later was already named by the engine's rules: its dang.toml declares that version rather than beta.20, so its code keeps working. Signed-off-by: Alex Suraci <alex@dagger.io>
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of the Dagger identifier casing work (dagger/dagger#13668) to the Python SDK. Reference implementation: dagger/dagger#14677, the in-repo version, now closed.
Release-blocking for the v1.0.0-beta.21 engine. From beta.21 the engine names modules with
engine/naminginstead of strcase (Pythoncom_url→ schemacomURL, enumReady→READY) and renames some core fields (shortSha→shortSHA, ...) without aliases. Without this PR, a scope generated in a beta.21 view selects names that don't exist, and calls through a module's own interfaces fail.The gate
New naming applies when the schema has
Query.formatIdentifiersand the engine is a release from v1.0.0-beta.21 on:formatIdentifiersis served only in views ≥ beta.21, exactly where the engine names schemas byengine/naming.formatIdentifiersin every v1 view, yet still name modules by strcase. That's why the engine-version check is there too. An unreadable version (devel) leaves the decision to the schema.helpers/nameswrites aSNAKE:UPPERCASEnames file, andpython -m codegen generate* -nreads itformatIdentifiersand-engine(Dang'sversion) ≥ beta.21dagger/mod/_naming.pycallsQuery.formatIdentifiersin the module's own session, by raw queryQuery.version≥ beta.21, then a probe offormatIdentifiers(missing field → old rules)Why codegen doesn't call
formatIdentifierspython-sdk.dangdeclaresengineVersion = "v1.0.0-beta.18"(the SDK floor), so its view is pre-cut and Dang can't typecheck aformatIdentifierscall. A privileged-nesting exec doesn't help either: its nested client gets the caller module's view.Following the chief's call (same as port-go),
helpers/namesvendors a verbatim copy ofengine/naming:naming/4-module-naming, with K8s and K3s as terms. The pin is inhelpers/names/naming/pin.go.e2e:names-helper-test-checkfails if the copied files differ fromengine/namingat the pinned commit. It also runsTestVectors(the copy formats the engine's owntestdata/vectors.jsonin every casing) and the helper's tests.WARNINGto stderr when a schema's version is newer thanCoveredVersion(v1.0.0), the release line the copy is known to cover. It warns rather than fails: dictionary additions are rare, engine releases aren't, and failing would block every user on every new engine.dictionary.go,format.go,naming.go,version.goandtestdata/vectors.jsonfromengine/namingat the new commit.Commitinpin.go.go mod tidy && go test ./...inhelpers/names.CoveredVersionif the commit is on a newer release line.engine/namingcommit finally lands on dagger/dagger main.What changes in generated code (beta.21 views only)
prerequisite_shas,experimental_with_all_gpus). When the legacy converter gave a different name (prerequisite_sh_as), it stays as a deprecated method that warns and forwards.ValueEnum(a new subclass ofdagger.client.base.Enum), withSCREAMING_SNAKEmembers:ImageMediaTypes.OCIMediaTypesisImageMediaTypes.OCI.@enumValueholds the module's own values stay plainEnums, unchanged.snake_to_camelcan't derive (call_id→callID) go through the existing_graphql_namestable.Generated entrypoints:
dang.tomldagger/dagger#14812 reads
[imports.Dagger] daggerfrom adang.tomlnext to the entrypoint, and serves an entrypoint without one at v1.0.0-beta.20. The entrypoint generated into a module (sdk/entrypoint/) now ships one:sdk/entrypoint/dang.tomldagger(or beta.20 if absent /true)dang.toml, older runtime manifests)v1.0.0-beta.20, so regenerating never silently changes its namingThe scope is generated in that version's view, so bindings and calls agree.
entrypoint/, the remote one, ships nodang.toml. It stays at beta.20, and so do its modules' scopes (core-schema'sv1.0.0-0maps to the same pre-cut view).--legacy-runtime) keepengineVersion= core-schema'sv1.0.0-0, i.e. pre-cut. That's the compatibility path; it's left alone here.FunctionCachePolicy: the old spellings (Never/PerSession/Default) are kept. Per final core: rename non-canonical core names from beta.21 dagger#14681 they stay valid in every view, so no version-dependent emission.Breaking changes (for users who opt into a beta.21 view)
.namechanges. A member found through a deprecated alias resolves to the canonical member:ImageMediaTypes.OCIMediaTypes.name == "OCI"..valueand what goes over the wire don't change.ValueEnuminstead ofEnum.FunctionCachePolicy.PerSessionas a distinct member in post-cut views, ...), and the #14677 "renamed core names" tables are intentionally not ported. Python method names mostly don't change (short_shaeither way).prerequisite_sh_as) and enum spellings emitDeprecationWarning.com_url→comURL). New modules get this by default through theirdang.toml.Dependencies
IdentifierCasingVersion.naming/4-module-naming. Theengine/namingpin comes from here.dang.toml.This PR must ship with or after those engine changes.
Follow-ups / open questions
scope.dang(clientSchema) reads a dependency client's schema withmember.source.withEngineVersion(view).clientSchemaIntrospectionJSON. Under #14669 that also changes the dependency's naming rules, so a client can disagree with what the engine serves across the beta.21 cut. It needs the upcomingclientSchemaIntrospectionJSON(view:)engine argument, from a sibling dagger/dagger PR.dang.tomllives in generated output. It sits insdk/entrypoint/, inside thesdk/tree generation rewrites. It's kept across generations, but a user who deletessdk/and regenerates drops back to beta.20 (pre-cut naming). A module-rootdang.tomlwould avoid that; this PR follows the spec of writing it next to the entrypoint.Testing
go test ./...andgo vetinhelpers/names: vectors, gate, engine gate, K8s term, SCREAMING_SNAKE = uppercased snake.e2e:sdk-test-check(603 passed): newtests/codegen/test_names.pyandtests/mod/test_naming.pycover both gates, names on/off, ValueEnum, aliases, packages, the global client, the CLI, interface call names, enum args/results, and the version gate.ruff checkandruff format --checkonsdk/.names-helper-test-check,entrypoint-version-check(new),static-scope-init-check,generate-scope-view-check,generate-scope-clients-check,generate-scope-global-client-check,generate-scope-plain-check,mod-generate-clients-check,entrypoint-kind-check.formatIdentifiersresponses, generated core at a beta.21 view, interface calls in a beta.21 module, and #14812 reading thedang.toml. The full e2e suite andengine-e2e:*weren't run either.